package com.bdqn.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bdqn.dto.Dto;
import com.bdqn.mapper.KeyWordMapper;
import com.bdqn.model.KeyWord;
import com.bdqn.service.KeyWordService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Service("KeyWordService")
public class KeyWordServiceImpl implements KeyWordService {

	@Autowired
	private KeyWordMapper keyWordMapper;

	@Override
	public PageInfo<KeyWord> selectAll() {
	
		PageHelper.startPage(1, 8);
		
		List<KeyWord> l = keyWordMapper.selectAll();
		
		PageInfo<KeyWord> pageInfo = new PageInfo<KeyWord>(l);
		
		pageInfo.setList(l);
	
		return pageInfo;
	}


	@Override
	public int insert(KeyWord kw) {
		return keyWordMapper.insert(kw);
	}

	@Override
	public int selectKeyWord(String keyWord) {
		return keyWordMapper.selectKeyWord(keyWord);
	}
//分页查询
	@Override
	public PageInfo<KeyWord> page(Dto dto) {
		
		PageHelper.startPage(dto.getPageNum(), 8);
		
		if((dto.getWord()) !=null) {
		
			List<KeyWord> l = keyWordMapper.selectLikeKeyWord(dto.getWord());
		
			PageInfo<KeyWord> pageInfo = new PageInfo<KeyWord>(l);
		
			pageInfo.setList(l);
			return pageInfo;
		}else {
			
			List<KeyWord> l = keyWordMapper.selectAll();
			
			PageInfo<KeyWord> pageInfo = new PageInfo<KeyWord>(l);
		
			pageInfo.setList(l);
			return pageInfo;
		}	
		
	}
//模糊查询
	@Override
	public PageInfo<KeyWord> selectLikeKeyWord(String keyWord) {
		

		List<KeyWord> l = keyWordMapper.selectLikeKeyWord(keyWord);
		
		PageInfo<KeyWord> pageInfo = new PageInfo<KeyWord>(l);
	
		pageInfo.setList(l);
		
		return pageInfo;
	
	}


	@Override
	public boolean selectByKeyWord(String keyWord) {
		
		int num = keyWordMapper.selectByKeyWord(keyWord);
		if(num>0) {
			return true;
		}else {
			return false;
		}
		
	}

	

	
	
	

}
